Skip to content

[Blazor] prevent infinite loop in SKCanvasView - #1889

Merged
mattleibow merged 2 commits into
mono:mainfrom
JensKrumsieck:main
Dec 14, 2021
Merged

[Blazor] prevent infinite loop in SKCanvasView#1889
mattleibow merged 2 commits into
mono:mainfrom
JensKrumsieck:main

Conversation

@JensKrumsieck

Copy link
Copy Markdown
Contributor

Description of Change

Prevents infinite resize loop - i don't know if this is the most elegant solution, but it works.

Added the following line to OnSizeChanged Event of Blazor SKCanvasView

if (Math.Round(canvasSize.Width * dpi) == newSize.Width && Math.Round(canvasSize.Height * dpi) == newSize.Height)
    return;

If Monitor scaling is applied in Windows Settings App, the view keeps multiplying the canvas size with the DPI (in my case being 1.25 for 125% scaling) in the Invalidate-Method.
The Canvas will be resized to the new size which results in the SizeWatcherInterop to fire its OnSizeChanged Event which will set canvasSize to newSize and calls Invalidate again to start infinite loop, also mentioned here:
#1838 (comment)

Bugs Fixed
#1838

API Changes
None

Behavioral Changes
None

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Updated documentation

@JensKrumsieck JensKrumsieck changed the title prevent infinite loop [Blazor] prevent infinite loop in SKCanvasView Dec 12, 2021

@mattleibow mattleibow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense. Just wondering if we should just be casting to int instead of rounding? That is what is happening on line 80.

Not sure if that was causing an issue and you already tried that. Feels like it should work.

@JensKrumsieck

Copy link
Copy Markdown
Contributor Author

You are right. I looked back at the console output from #1838 (comment)

DPI: 1,25 -> predicting: 1952,5: 1463,75
1952 : 1463

It cuts the digits after the comma instead of rounding.
I appended 5385f9d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants